package cn.zd.demo1;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerTabStrip;
import androidx.viewpager.widget.ViewPager;

import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.Toast;

import cn.zd.demo1.adapter.MyViewPageAdapter;

public class ViewPageActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {

    private ViewPager vp_1;
    private PagerTabStrip vp_pst1;
    private MyViewPageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Toast.makeText(this,this.getClass().getName(),Toast.LENGTH_LONG).show();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_viewpage);
        vp_1 = findViewById(R.id.vp_1);
        adapter = new MyViewPageAdapter(this);
        vp_1.setAdapter(adapter);
        vp_1.addOnPageChangeListener(this);

        vp_pst1 = findViewById(R.id.vp_pst1);
        vp_pst1.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
        vp_pst1.setTextColor(Color.GREEN);
    }

    /**
     *
     * @param position Position index of the first page currently being displayed.
     *                 Page position+1 will be visible if positionOffset is nonzero.
     *                 当前页面序号
     * @param positionOffset Value from [0, 1) indicating the offset from the page at position.
     *                       页面偏移百分比
     * @param positionOffsetPixels Value in pixels indicating the offset from position.
     *                             便宜距离
     */
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        Toast.makeText(this,"滑到了："+adapter.getData(position).getName(),Toast.LENGTH_SHORT).show();
    }

    /**
     * 翻页状态
     * 0： 静止
     * 1： 正在滑动
     * 2： 滑动完毕
     * @param state The new scroll state.
     */
    @Override
    public void onPageScrollStateChanged(int state) {

    }

}